package com.servlet.user;

import com.bean.Salary;
import com.service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@WebServlet("/user/listSalarySelf")
public class ListSalarySelfServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=(String) req.getSession().getAttribute("userName");
        EmployeeService employeeService=new EmployeeService();
        Date date =new Date();
        SimpleDateFormat formattery = new SimpleDateFormat("yyyy");
        String year = formattery.format(date);
        List<Salary> salarys = employeeService.getSalaryByuser(id,year);

        req.setAttribute("salarys",salarys);
        req.getRequestDispatcher("usersearchsalary.jsp").forward(req, resp);
    }
}
